package com.example.myapplication5;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;

public class ProjectAdapter extends BaseAdapter {
    private Context context;
    private List<Project> projectList;

    public ProjectAdapter(Context context, List<Project> projectList) {
        this.context = context;
        this.projectList = projectList;
    }

    @Override
    public int getCount() {
        return projectList.size();
    }

    @Override
    public Object getItem(int position) {
        return projectList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_project, null);
        }
        ImageView ivProject = convertView.findViewById(R.id.iv_project);
        TextView tvTitle = convertView.findViewById(R.id.tv_title);
        TextView tvDesc = convertView.findViewById(R.id.tv_desc);
        // 设置数据
        Project project = projectList.get(position);
        tvTitle.setText(project.title);
        tvDesc.setText(project.desc);
        ivProject.setImageResource(project.imageRes);
        return convertView;
    }
}
